package com.gitee.demo.ah;

import com.gitee.demo.constants.HttpHeaderContentTypeEnum;
import com.gitee.demo.httpclient.MyHttpsClient;
import com.gitee.demo.utils.AESUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tao on 2019/12/12
 */
public class AHIdentifyServiceHttps {

    public static String httpsPostLogin(String account, String password, String loginurl) {
        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("account", account);
        paramsMap.put("password", AESUtils.encrypt(password));

        //消息头
        Map<String, String> headersMap = new HashMap<String, String>();
        headersMap.put("Content-Type", HttpHeaderContentTypeEnum.JSON.getDesc());

        //post请求
        Object result = null;
        try {
            result = MyHttpsClient.sendPostHttps("https://182.168.11/nodes/register", paramsMap, headersMap, HttpHeaderContentTypeEnum.JSON.getKey());
        } catch (Throwable e) {
            return null;
        }

        return AESUtils.parseToken(result);
    }

    public static String httpsGetScanTask(String token, String scantaskurl) {
        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();

        //消息头
        Map<String, String> headersMap = new HashMap<String, String>();
        headersMap.put("Cookie", "JSESSIONID=" + token);

        //get请求
        Object result = null;
        try {
            result = MyHttpsClient.sendGetHttps(scantaskurl, paramsMap, headersMap);
        } catch (Throwable e) {
            return null;
        }

        return AESUtils.parseRecord(result);
    }

}
